// *************************************************************************************************
//
//	Copyright Area
//	 
//
// *************************************************************************************************
// Backlight functions.
// *************************************************************************************************


// *************************************************************************************************
// Include section

// system
#include "project.h"

// driver
#include "display.h"
#include "ports.h"

// logic
#include "user.h"


// *************************************************************************************************
// Prototypes section

// *************************************************************************************************
// Defines section

// *************************************************************************************************
// Global Variable section

// *************************************************************************************************
// Return this port to it's initial configuration (see init_buttons at ports.c)
void backlight_input( void )
{
    if( (BUTTONS_DIR & BUTTON_BACKLIGHT_PIN) == BUTTON_BACKLIGHT_PIN )
    {
        // Set button port to input 
        BUTTONS_DIR &= ~BUTTON_BACKLIGHT_PIN; 
    
        // Enable internal pull-down
        BUTTONS_OUT &= ~BUTTON_BACKLIGHT_PIN; 
        BUTTONS_REN |= BUTTON_BACKLIGHT_PIN; 
    
        // IRQ trigger on rising edge
        BUTTONS_IES &= ~BUTTON_BACKLIGHT_PIN;   
    
        // Reset IRQ flag
        BUTTONS_IFG &= ~BUTTON_BACKLIGHT_PIN;  
    
        // Enable button interrupt
        BUTTONS_IE |= BUTTON_BACKLIGHT_PIN;
    }
}

// Set this port as output high
void backlight_output( void )
{
    if( (BUTTONS_DIR & BUTTON_BACKLIGHT_PIN) == 0 )
    {
        // Disable button interrupt
        BUTTONS_IE &= ~BUTTON_BACKLIGHT_PIN;  
        
        // Reset IRQ flag
        BUTTONS_IFG &= ~BUTTON_BACKLIGHT_PIN; 
        
        // Set output value to high
        BUTTONS_OUT |= BUTTON_BACKLIGHT_PIN;
    
        // Set button port to output 
        BUTTONS_DIR |= BUTTON_BACKLIGHT_PIN; 
    }
}